package cn.itsource.org.service.impl;

import cn.itsource.basic.util.PageList;
import cn.itsource.org.domain.Department;
import cn.itsource.org.mapper.DepartmentMapper;
import cn.itsource.org.query.DepartmentQuery;
import cn.itsource.org.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public void save(Department department) {
        departmentMapper.save(department);

    }

    @Override
    public void remove(Long id) {
        departmentMapper.remove(id);

    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    @Transactional(readOnly = true)
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        //创建分页对象
        PageHelper.startPage(departmentQuery.getPageNum(), departmentQuery.getPageSize());
        //查询所有
        List<Department> loadAll = departmentMapper.loadAll();
        //创建分页对象
        PageInfo<Department> departmentPageInfo = new PageInfo<>(loadAll);
        return new PageList<>(departmentPageInfo.getTotal(),departmentPageInfo.getList());

    }
}
